
/'	FreeBASIC does not have an Apple Target (no fbc port to mac os yet)
#ifdef __APPLE__
#	import "TargetConditionals.h"
#endif

#if (Defined CP_USE_CGPOINTS) Or (defined TARGET_OS_IPHONE)
#	if TARGET_OS_IPHONE
#		import <CoreGraphics/CGGeometry.h>
#	elif TARGET_OS_MAC
#		import <ApplicationServices/ApplicationServices.h>
#	endif

#	if defined(__LP64__) And __LP64__
#		define CP_USE_DOUBLES 1
#	else
#		define CP_USE_DOUBLES 0
#	endif
#endif
'/

'' FreeBASIC: import the c runtime math library (for sqrt/sqrtf)
#include "crt/math.bi"

#ifndef CP_USE_DOUBLES
  '' use doubles by default for higher precision
  #define CP_USE_DOUBLES 1
#endif

#if CP_USE_DOUBLES
	type cpFloat as double
#	define cpfsqrt sqrt
#	define cpfsin sin
#	define cpfcos cos
#	define cpfacos acos
#	define cpfatan2 atan2
#	define cpfmod fmod
#	define cpfexp exp
#	define cpfpow pow
#	define cpffloor floor
#	define cpfceil ceil
#else
	type cpFloat as single
#	define cpfsqrt sqrtf
#	define cpfsin sinf
#	define cpfcos cosf
#	define cpfacos acosf
#	define cpfatan2 atan2f
#	define cpfmod fmodf
#	define cpfexp expf
#	define cpfpow powf
#	define cpffloor floorf
#	define cpfceil ceilf
#endif

#ifdef INFINITY
#	undef INFINITY
#	define INFINITY (1e31)
#endif

#ifndef M_PI
#	define M_PI 3.14159265358979323846264338327950288
#endif

#ifndef M_E
#	define M_E 2.71828182845904523536028747135266250
#endif

function cpfmax cdecl( a as cpFloat, b as cpFloat ) as cpFloat
	return iif( a > b, a, b )
end function

function cpfmin cdecl( a as cpFloat, b as cpFloat ) as cpFloat
	return iif( a < b, a, b )
end function

function cpfabs cdecl( n as cpFloat ) as cpFloat
	return iif( n < 0, -n, n )
end function

function cpfclamp cdecl( f as cpFloat, min as cpFloat, max as cpFloat ) as cpFloat
	return cpfmin( cpfmax( f, min ), max )
end function

function cpfclamp01 cdecl( byval f as cpFloat ) as cpFloat
	return cpfmax( 0.0, cpfmin( f, 1.0 ) )
end function

function cpflerp cdecl( f1 as cpFloat, f2 as cpFloat, t as cpFloat ) as cpFloat
	return f1 * ( 1.0 - t ) + f2 * t
end function

function cpflerpconst cdecl( f1 as cpFloat, f2 as cpFloat, d as cpFloat ) as cpFloat
	return f1 + cpfclamp( f2 - f1, -d, d )
end function

type cpHashValue		as unsigned integer

'' Oh C, how we love to define our own boolean types to get compiler compatibility
#ifdef CP_BOOL_TYPE
	type cpBool as CP_BOOL_TYPE
#else
	type cpBool as integer
#endif

#ifndef cpTrue
#	define cpTrue 1
#endif

#ifndef cpFalse
#	define cpFalse 0
#endif

#ifdef CP_DATA_POINTER_TYPE
	type cpDataPointer		as CP_DATA_POINTER_TYPE
#else
	type cpDataPointer		as any ptr
#endif

#ifdef CP_COLLISION_TYPE_TYPE
	type cpCollisionType	as CP_COLLISION_TYPE_TYPE
#else
	type cpCollisionType	as unsigned integer
#endif

#ifdef CP_GROUP_TYPE
	type cpGroup			as CP_GROUP_TYPE
#else
	type cpGroup			as unsigned integer
#endif

#ifdef CP_LAYERS_TYPE
	type cpLayers			as CP_LAYERS_TYPE
#else
	type cpLayers			as unsigned integer
#endif

#ifdef CP_TIMESTAMP_TYPE
	type cpTimestamp as CP_TIMESTAMP_TYPE
#else
	type cpTimestamp as unsigned integer
#endif

#ifndef CP_NO_GROUP
#	define CP_NO_GROUP (cast(cpGroup, 0))
#endif

#ifndef CP_ALL_LAYERS
#	define CP_ALL_LAYERS (not cast(cpLayers, 0))
#endif

'' CGPoints are structurally the same, and allow
'' easy interoperability with other Cocoa libraries
#ifdef CP_USE_CGPOINTS
	type cpVect as CGPoint
#else
'' Chipmunk's 2D vector type.
'' @addtogroup cpVect
	type cpVect : as cpFloat x, y : end type
#endif
